﻿' Compiler Options:
Option Explicit On
Option Strict On
Option Infer Off

Public Class WordsToSpellMW
    Inherits WordMW

    ' TODOMW:  This class will handle getting the words from a file.

    ' TODOMW:   Next step is to use a VB List instead of an array.
    '           Also look at the Dictionary Object.
    Dim WordsArray(4, 2) As String

    Private wordsIndexValue As Integer
    Public Property wordsIndex() As Integer
        Get
            Return wordsIndexValue
        End Get
        Set(value As Integer)
            wordsIndexValue = value
        End Set
    End Property




    Public Sub New()
        LoadWords()
    End Sub

    Private Function LoadWords() As Boolean

        Dim result As Boolean

        ' TODOMW: Finish code. Test if WordsArray has been populated if not then return false.

        WordsArray = {{"Hello", "World", "Happy", "People", "Laugh"}, {"Hello there. How are you.", "The world is a big place.", "I am happy to see you.", "How many people are coming to the party tonigh.", "Did you laugh at the comedian at last nights show?"}, {"Used to greet someone, answer the telephone, or express surprise.", "All of the people, societies, and institutions on the earth.", "Feeling or showing pleasure or contentment.", "Human beings in general or considered collectively.", "To make the noise with your voice that shows you think something is funny"}}

        ' Fill the first Word, context and definition.
        word = WordsArray(0, 0)
        context = WordsArray(1, 0)
        definition = WordsArray(2, 0)

        ' Fill Current Character variable.
        currentCharacter = CChar(word.Substring(characterIndex))

        Return result
    End Function


    Public Function NextCharacter() As Boolean
        ' Get the next character of the word to spell.

        Dim result As Boolean

        ' First pass the current correct character to current correct characters variable.
        currentCharactersCorrect += word.Chars(characterIndex)

        If Not wordComplete Then
            ' Incrament to the next character in word.
            characterIndex += 1
        End If

        If characterIndex = word.Length Then
            '>> All characters of the word to spell have been entered.
            result = False
            ' Flag that the word has been completed.
            wordComplete = True
        Else
            ' >> Get next character in word to spell.
            result = True
            ' Move to the next character in word to spell for USER to guess.
            currentCharacter = CChar(word.Chars(characterIndex))
        End If

        Return result
    End Function


    Public Function NextWord(ByVal hintGiven As Boolean) As Boolean
        Dim result As Boolean

        ' TODOMW: finish code.

        ' New Word so Reset characterIndex
        characterIndex = 0
        ' >> Reset word varaibles.
        wordComplete = False

        ' IMPORTANT: Reset word, context and definition. So they do not propagate to a new word if it does not include a context or definition.
        word = Nothing
        context = Nothing
        definition = Nothing
        currentCharactersCorrect = Nothing

        ' WARNING:  Used the short hand += operator but did not work.
        '           wordsIndex += wordsIndex <--- Did NOT work. 
        '           I think it is because the initial word is initialized by Microsoft as Nothing.
        '           wordsIndex = wordsIndex + 1 <--- Works.
        '           Had to use the long hand version of wordsIndex = wordsIndex + 1 for it to work.
        ' Increment the next index for the Array.
        wordsIndex = wordsIndex + 1

        ' TODOMW: Use WordArray.UpperBound(0) instead of Count.
        If wordsIndex > WordsArray(0, 0).Count - 1 Then
            result = False
        Else
            result = True

            ' TODOMW:   Implement hintGiven boolean varaible.
            '           If hintGiven then go on to next word but do not remove from list of words to test.
            '           Word will be tested again at the end of the word list.

            If hintGiven Then
                ' Do NOT remove word from list and get next word.

                ' TODOMW: Finish code.
            Else
                ' Remove word from list then get next word.

                ' TODOMW: Finish code.

            End If


            ' TODOMW:   Implement random word list selection.

            ' >> Get the next word to spell.
            word = WordsArray(0, wordsIndex)
            context = WordsArray(1, wordsIndex)
            definition = WordsArray(2, wordsIndex)

            ' Place the first character in the word to spell.
            currentCharacter = word.Chars(0)
            ' Reset HintGiven property.
            hintGiven = False
        End If

        Return result
    End Function


    Public Function NextLesson() As Boolean

        Dim result As Boolean

        ' TODOMW: Finish code.

        Return result
    End Function



End Class
